
package FinalProject;


public class Manager extends Employee {
    private double monthlySalary;
    private double bonus;
    private int teamSize;

    public Manager(String name, String id, String department, double monthlySalary) {
        super(name, id, department);
        this.monthlySalary = monthlySalary;
        this.bonus = 0;
        this.teamSize = 0;
    }

    @Override
    public double calculateSalary() throws WorkHourException {
        validateBonus();

        // 基本月薪 + 奖金 + 团队管理津贴
        double teamAllowance = teamSize * 200; // 每人200元团队管理津贴

        return monthlySalary + bonus + teamAllowance;
    }

    @Override
    public String generatePaySlip() throws WorkHourException {
        double salary = calculateSalary();
        double teamAllowance = teamSize * 200;

        StringBuilder paySlip = new StringBuilder();
        paySlip.append("=============== 工资条 ===============\n");
        paySlip.append(String.format("姓名: %-10s 工号: %s\n", name, id));
        paySlip.append(String.format("部门: %-10s 类型: %s\n", department, getEmployeeType()));
        paySlip.append(String.format("团队规模: %d 人\n", teamSize));
        paySlip.append("--------------------------------------\n");
        paySlip.append(String.format("基本月薪: %.2f 元\n", monthlySalary));
        paySlip.append(String.format("奖金: %.2f 元\n", bonus));
        paySlip.append(String.format("团队津贴: %.2f 元\n", teamAllowance));
        paySlip.append("--------------------------------------\n");
        paySlip.append(String.format("应发薪资: %.2f 元\n", salary));
        paySlip.append("======================================\n");

        return paySlip.toString();
    }

    @Override
    public String getEmployeeType() {
        return "管理人员";
    }

    private void validateBonus() throws WorkHourException {
        if (bonus < 0) {
            throw new WorkHourException("奖金不能为负数: " + bonus + " 元");
        }
    }

    // Getter和Setter
    public void setBonus(double bonus) {
        this.bonus = bonus;
    }

    public void setTeamSize(int teamSize) {
        this.teamSize = teamSize;
    }

    public double getMonthlySalary() {
        return monthlySalary;
    }

    public double getBonus() {
        return bonus;
    }

    public int getTeamSize() {
        return teamSize;
    }
}